//
//  ShopWordsCell.m
//  BaseFrame
//
//  Created by wingfac on 2017/8/15.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "ShopWordsCell.h"
#import "NSString+Util.h"
@interface ShopWordsCell()
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *wordsLabel;

@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UIView *line;
@end
@implementation ShopWordsCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = 0;
        self.backgroundColor = getColor(@"ebebf1");
        [self.contentView addSubview:self.bgView];
        [self.bgView addSubview:self.titleLabel];
        [self.bgView addSubview:self.wordsLabel];
        [self.contentView addSubview:self.line];
    }
    return self;
}
- (UIView *)bgView{
    if(!_bgView){
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(5/WIDTH_5S_SCALE, 0, SCREEN_WIDTH-10/WIDTH_5S_SCALE, 60)];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}
- (UIView *)line{
    if(!_line){
        _line = [[UIView alloc] init];
        _line.backgroundColor = getColor(dividerColor);
    }
    return _line;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = DEF_FontSize_16;
        _titleLabel.text = @"买家留言：";
        _titleLabel.textColor = getColor(mainColor);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        
    }
    return _titleLabel;
}
- (UILabel *)wordsLabel {
    if (!_wordsLabel) {
        _wordsLabel = [[UILabel alloc]init];
        _wordsLabel.font = DEF_FontSize_14;
        _wordsLabel.textAlignment = NSTextAlignmentLeft;
        _wordsLabel.numberOfLines = 0;//根据最大行数需求来设置
        
    }
    return _wordsLabel;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGSize maximumLabelSize = CGSizeMake(SCREEN_WIDTH-2*10, MAXFLOAT);//labelsize的最大值
    //关键语句
    CGSize expectSize = [_wordsLabel sizeThatFits:maximumLabelSize];
    
    _bgView.frame =CGRectMake(5/WIDTH_5S_SCALE, 0, SCREEN_WIDTH - 10/WIDTH_5S_SCALE, expectSize.height+40/WIDTH_5S_SCALE);
    _titleLabel.frame =CGRectMake(5/WIDTH_5S_SCALE, 0, expectSize.width, 30/WIDTH_5S_SCALE);
    
    _wordsLabel.frame = CGRectMake(5/WIDTH_5S_SCALE, 20/WIDTH_5S_SCALE, expectSize.width, expectSize.height+30/WIDTH_5S_SCALE);

    _line.frame = CGRectMake(10/WIDTH_5S_SCALE, expectSize.height+39.5/WIDTH_5S_SCALE, SCREEN_WIDTH-15/WIDTH_5S_SCALE, 0.5);
}

- (void)setWordsString:(NSString *)words{
    _titleLabel.text = @"买家留言：";
    _wordsLabel.text = words;
    [self.layer setNeedsLayout];
}


+(CGFloat)getCellHeight:(id)obj {
    NSString *string = (NSString *)obj;
    
    return [string heightForFont:DEF_FontSize_14 width:SCREEN_WIDTH-10/WIDTH_5S_SCALE]+0.5+40/WIDTH_5S_SCALE;
}

@end
